﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class ThanhToan : System.Web.UI.Page
{
    private decimal sotien;
    protected void Page_Load(object sender, EventArgs e)
    {
        sotien = decimal.Parse(Request.QueryString["sotien"]);
        lblSoTien.Text = String.Format("{0:#,##0;Nothing}", sotien) + " VNĐ";
    }
    protected void btnThanhToan_Click(object sender, EventArgs e)
    {
        UpdateDonDatHang();
        lblStatus.Text = "Giao dịch thành công";
    }

    public void UpdateDonDatHang()
    {
        DonDatHangBUS objOrders =
            new DonDatHangBUS(TGDDConfiguration.DbConnectionString);
        // Create the order and store the order ID
        Guid userId = new Guid(Session["g_UserId"].ToString());
        // Return ID of DonDatHang
        DataSet objOrdersDS = objOrders.CreateOrder(
            AccessGioHang.idGioHang, userId);
        var objBUS = new DonDatHangBUS(TGDDConfiguration.DbConnectionString);
        var objNDBUS = new NguoiDungBUS(TGDDConfiguration.DbConnectionString);

        var objDTO = new DonDatHangDTO
        {
            Id = int.Parse(objOrdersDS.Tables[0].Rows[0][0].ToString()),
            TenKhachHang = objNDBUS.SelectNguoiDung(userId).Tables[0].Rows[0]["Ten"].ToString(),
            TenNguoiNhan = txtTenNguoiNhan.Text,
            SDTNguoiNhan = txtSDTNguoiNhan.Text,
            DiaChiNguoiNhan = txtDiaChiNguoiNhan.Text
        };
        objBUS.InitDonDatHangInfo(objDTO);
        Response.Redirect("HoaDonMuaHang.aspx?id=" + objDTO.Id);
    }
}
